﻿using System;
using System.Collections.Generic;
using ControleRepresentante.Migration.Models;
using ControleRepresentante.Migration.Repositories;

namespace ControleRepresentante.Migration.Steps
{
    internal class ContaMigrationStep : MigrationStepBase
    {
        public override void Migrate(Guid representanteId, MigrationStatus migrationStatus, ControleRepresentanteRepository controleRepresentanteRepository, ZTRepository ztRepository, Guid userId)
        {
            migrationStatus.CurrentStep = "Migrate Contas";

            int total = ztRepository.GetTotalContas();

            IEnumerable<ZTConta> ztContas = ztRepository.GetContas();

            int index = 0;
            foreach (ZTConta ztConta in ztContas)
            {
                Guid fabricaId = GetFabricaId(ztConta.IdFabrica);
                controleRepresentanteRepository.CreateConta(fabricaId, true, ztConta.Banco, ztConta.Agencia, ztConta.Conta);
                migrationStatus.SetCurrentProgress(++index, total);
            }
        }
    }
}